<template>
    <div class="app-container">
        <!-- 添加或修改员工入职对话框 -->
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">

            <el-card class="box-card">
                <div slot="header" class="clearfix">
                    <span>基础信息</span>
                </div>
                <el-row>
                    <el-col :xs="16" :sm="16" :md="16" :lg="16" :xl="16">
                        <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="姓名" prop="realName">
                                <el-input v-model="form.realName" placeholder="请输入姓名"/>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="学号" prop="studentCode">
                                <el-input v-model="form.studentCode" placeholder="请输入学号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="性别" prop="sex">
                                <el-radio-group v-model="form.sex">
                                    <el-radio v-for="dict in dict.type.sys_user_sex" :key="dict.value"
                                              :label="dict.value">{{ dict.label }}
                                    </el-radio>
                                </el-radio-group>
                            </el-form-item>
                        </el-col>
<!--                        <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">-->
<!--                            <el-form-item label="最高学历" prop="education">-->
<!--                                <el-radio-group v-model="form.education">-->
<!--                                    <el-radio v-for="dict in dict.type.education_list" :key="dict.value"-->
<!--                                              :label="dict.value">{{ dict.label }}-->
<!--                                    </el-radio>-->
<!--                                </el-radio-group>-->
<!--                            </el-form-item>-->
<!--                        </el-col>-->
                        <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="身份证号" prop="idNum">
                                <el-input v-model="form.idNum" placeholder="请输入身份证号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="出生日期" prop="birthdate">
                                <el-date-picker clearable v-model="form.birthdate" type="date" value-format="yyyy-MM-dd"
                                                placeholder="请选择出生日期"></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="电话" prop="phone">
                                <el-input v-model="form.phone" placeholder="请输入电话"/>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="邮箱" prop="mail">
                                <el-input v-model="form.mail" placeholder="请输入邮箱"/>
                            </el-form-item>
                        </el-col>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="">
                            <image-upload v-model="form.avatar"/>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-card>

            <el-card class="box-card top15">
                <div slot="header" class="clearfix">
                    <span>扩展信息</span>
                </div>
                <el-row>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="婚姻状况">
                            <el-radio-group v-model="form.marryStatus">
                                <el-radio v-for="dict in dict.type.marry_status" :key="dict.value" :label="dict.value">
                                    {{ dict.label }}
                                </el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="身高" prop="height">
                            <el-input v-model="form.height" placeholder="请输入身高（单位厘米cm）"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="体重" prop="weight">
                            <el-input v-model="form.weight" placeholder="请输入体重（单位千克kg）"/>
                        </el-form-item>
                    </el-col>

                </el-row>
                <el-row>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="民族" prop="nation">
                            <el-select v-model="form.nation" placeholder="请选择民族">
                                <el-option v-for="dict in dict.type.nation_list" :key="dict.value"
                                           :label="dict.label" :value="dict.value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="政治面貌">
                            <el-radio-group v-model="form.political">
                                <el-radio v-for="dict in dict.type.political_status" :key="dict.value"
                                          :label="dict.value">{{ dict.label }}
                                </el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="入党时间" prop="joinpartyDate">
                            <el-date-picker clearable v-model="form.joinpartyDate" type="date" value-format="yyyy-MM-dd"
                                            placeholder="请选择入党时间"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="英语水平">
                            <el-radio-group v-model="form.englishLevel">
                                <el-radio v-for="dict in dict.type.language_level" :key="dict.value"
                                          :label="dict.value">{{ dict.label }}
                                </el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="其他语言" prop="otherLanguage">
                            <el-input v-model="form.otherLanguage" placeholder="请输入其他语言"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="语言水平">
                            <el-radio-group v-model="form.otherLanguageLevel">
                                <el-radio v-for="dict in dict.type.language_level" :key="dict.value"
                                          :label="dict.value">{{ dict.label }}
                                </el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="驾照类型">
                            <el-checkbox-group v-model="form.driverslicenseType">
                                <el-checkbox v-for="dict in dict.type.driverslicense_type" :key="dict.value"
                                             :label="dict.value">{{ dict.label }}
                                </el-checkbox>
                            </el-checkbox-group>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-card>

            <el-card class="box-card top15">
                <div slot="header" class="clearfix">
                    <span>户籍信息</span>
                </div>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="籍贯" prop="nativePlace">
                            <el-input v-model="form.nativePlace" placeholder="请输入籍贯"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="派出所" prop="nativeplacePolice">
                            <el-input v-model="form.nativeplacePolice" placeholder="请输入户籍所在派出所"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="户籍地址" prop="nativeplaceAddress">
                            <el-input v-model="form.nativeplaceAddress" placeholder="请输入户籍所在地址"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="户籍邮编" prop="nativeplacePostcode">
                            <el-input v-model="form.nativeplacePostcode" placeholder="请输入户籍所在地邮编"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="家庭地址" prop="homeAddress">
                            <el-input v-model="form.homeAddress" placeholder="请输入家庭地址"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="地址邮编" prop="homeAddressPostcode">
                            <el-input v-model="form.homeAddressPostcode" placeholder="请输入嘉定地址邮编"/>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="现居住地" prop="nowAddress">
                            <el-input v-model="form.nowAddress" placeholder="请输入现居住地"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="居地邮编" prop="nowAddressPostcode">
                            <el-input v-model="form.nowAddressPostcode" placeholder="请输入现居住地邮编"/>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-card>

            <el-card class="box-card top15">
                <div slot="header" class="clearfix">
                    <span>紧急联系人</span>
                </div>
                <el-row>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="姓名" prop="urgentContact">
                            <el-input v-model="form.urgentContact" placeholder="请输入紧急联系人姓名"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="关系" prop="urgentContactRel">
                            <el-radio-group v-model="form.urgentContactRel">
                                <el-radio v-for="dict in dict.type.family_relation_type" :key="dict.value"
                                          :label="dict.value">{{ dict.label }}
                                </el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                        <el-form-item label="电话" prop="urgentContactPhone">
                            <el-input v-model="form.urgentContactPhone" placeholder="请输入紧急联系人电话"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
                        <el-form-item label="联系地址" prop="urgentContactAddress">
                            <el-input v-model="form.urgentContactAddress" placeholder="请输入紧急联系人地址"/>
                        </el-form-item>
                    </el-col>
                </el-row>

            </el-card>

            <el-card class="box-card top15">
                <div slot="header" class="clearfix">
                    <span>其他</span>
                </div>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="技术职称职业资格" prop="qualification">
                            <el-input v-model="form.qualification" rows="5" type="textarea" placeholder="请输入技术职称职业资格"/>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="科研著作" prop="publications">
                            <el-input v-model="form.publications" rows="5" type="textarea" placeholder="请输入科研著作"/>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="奖惩情况" prop="rewardPunish">
                            <el-input v-model="form.rewardPunish" rows="5" type="textarea" placeholder="请输入奖惩情况"/>
                        </el-form-item>
                    </el-col>
                </el-row>



            </el-card>



        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
    </div>
</template>

<script>
import {listStudent, getStudent, delStudent, addStudent, updateStudent} from "@/api/stu/student";
export default {
    name: "student",
    dicts: ['political_status','education_list','sys_yes_no','family_relation_type', 'nation_list', 'marry_status', 'language_level', 'sys_user_sex', 'driverslicense_type'],
    data() {
        return {
            // 表单参数
            form: {
                driverslicenseType: []
            },
            // 表单校验
            rules: {
                realName: [
                    {required: true, message: "姓名不能为空", trigger: "blur"}
                ],
                // sex: [
                //     {required: true, message: "性别不能为空", trigger: "blur"}
                // ]
            }
        };
    },
    created() {
        const formId = this.$route.params && this.$route.params.formId;
        if(formId){
            this.form.id = formId;
            this.getDetailData(formId);
        }
    },
    mounted() {
        console.log(this.dict.type.driverslicense_type);
    },
    methods: {
        //  获取单据信息
        getDetailData(id) {
            getStudent(id).then(response => {
                this.form = response.data;
                this.form.driverslicenseType = this.form.driverslicenseType.split(",");
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    this.form.driverslicenseType = this.form.driverslicenseType.join(",");
                    if (this.form.id != null) {
                        updateStudent(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.closeThisPage();
                        });
                    } else {
                        addStudent(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.closeThisPage();
                        });
                    }
                }
            });
        },
        closeThisPage(){
            const obj = { path: "/stu/student" };
            this.$tab.closeOpenPage(obj);
        }
    }
};
</script>
<style lang="scss" scoped>
</style>
